﻿@model Isaac.Joy.Identity.Web.DtCms.Models.UserListViewModel
@{
    ViewBag.Title = "用户管理";
    Layout = Url.BundleContent("~/Views/Shared/_Layout.cshtml");
    Model.PageInfor.PageUrl = ((index, size) => Url.Action("Index", new { pi = index, ps = size, wd = Model.KeywordFliter, rid = Model.RoleFliter }));
}
<!--导航栏-->
<div class="location">
    <a href="javascript:history.back(-1);" class="back"><i></i><span>返回上一页</span></a>
    <a class="home"><i></i><span>控制面板</span></a>
    <i class="arrow"></i>
    <span>用户管理</span>
</div>
<!--/导航栏-->
<!--工具栏-->
<div class="toolbar-wrap">
    <div id="floatHead" class="toolbar">
        <div class="l-list">
            <ul class="icon-list">
                <li><a class="add" href="@Url.Action("Add")"><i></i><span>新增</span></a></li>
                <li><a class="all" href="script:;" onclick="checkAll(this);"><i></i><span id="txtall">全选</span></a></li>
                @*<li><a id="btnSave" class="save" href="javascript:;"><i></i><span>保存</span></a></li>*@
                <li><a id="btnDelete" class="del" href="javascript:;"><i></i><span>删除</span></a></li>
            </ul>
            <div class="menu-list">
                <div class="rule-single-select">
                    <select name="ddlGroupId" id="ddlRole">
                        @if (Model.RoleFliter == null || Model.Roles.All(x => x.Id != Model.RoleFliter))
                        {
                            <option selected="selected" value="">所有角色</option>
                        }
                        else
                        {
                            <option value="">所有角色</option>
                        }
                        @foreach (var role in Model.Roles)
                        {
                            if (Model.RoleFliter != role.Id)
                            {
                            <option value="@role.Id">@role.Name</option>}
                            else
                            {
                            <option selected="selected" value="@role.Id">@role.Name</option>
                            }
                        }
                    </select>
                </div>
            </div>
        </div>
        <div class="r-list">
            <input name="txtKeywords" type="text" id="txtKeywords" class="keyword" value="@Model.KeywordFliter" />
            <a id="lbtnSearch" class="btn-search" href="###">查询</a>
        </div>
    </div>
</div>
<!--/工具栏-->

<!--文字列表-->
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable">
    <tr>
        <th width="6%">选择</th>
        <th align="left">账号</th>
        <th align="left" width="26%">角色</th>
        <th align="left" width="22%">创建时间</th>
        <th width="8%">操作</th>
    </tr>
    @{ var rowindex = 0; }
    @foreach (var user in Model.Data)
    {
        <tr>
            @{
        var rowctlid = "rptList_hidId_" + @rowindex;
        var rowchkid = "rptList_chkId_" + @rowindex;
        rowindex++;
 }
            <td align="center">
                <span class="aspNetDisabled checkall" style="vertical-align: middle;">
                    <input id="@rowchkid" type="checkbox" name="rptList$ctl01$chkId" /></span>
                <input type="hidden" name="rptList$ctl01$hidId" id="@rowctlid" value="@user.Id" />
            </td>
            <td><a href="@Url.Action("Edit", new { id = user.Id })">@user.Account</a></td>
            <td>@user.Role.Name</td>
            <td>@user.CreateTime.ToString("yyyy-MM-dd")</td>
            <td align="center"><a href="@Url.Action("Edit", new { id = user.Id })">修改</a></td>
        </tr>
    }

</table>

<!--/文字列表-->

<!--内容底部-->
<div class="line20"></div>
@{
    Html.RenderPartial("Page");
}
<!--/内容底部-->
@section scripts{
    <script type="text/javascript">
        $(function () {
            $("#ddlRole").change(function () {
                var url = "@Html.Raw(Url.Action("Index", new { pi = 1, ps = Model.PageInfor.Size, wd = Model.KeywordFliter }))";
                document.location.href = url + "&rid=" + $("#ddlRole").val();
            });

            $("#lbtnSearch").click(function () {
                var url = "@Html.Raw(Url.Action("Index", new { pi = 1, ps = Model.PageInfor.Size, rid = Model.RoleFliter }))";
                document.location.href = url + "&wd=" + $("#txtKeywords").val();
            });

            $("#btnDelete").click(function () {
                var delString = "";
                for (var i = 0; i < $("#txtPageNum").val() ; i++) {
                    if ($("#rptList_chkId_" + i).is(':checked') == true) {
                        var delStr = $("#rptList_hidId_" + i).val();
                        delString += delStr + ",";
                    }
                }
                if (delString != "") {
                    $.get("@Html.Raw(Url.Action("AjaxDelete"))", { strId: delString }, function (response) {
                        var data = JSON.parse(response);
                        errorCode.getMsg(data, function () {
                            if (data.success) {
                                $.dialog.alert('删除成功！', function () {
                                    document.location.reload();
                                }, null, "提示");
                            } else {
                                $.dialog.alert('删除失败！');
                            }
                        }, function (e) {
                            $.dialog.alert(data.msg == '' ? e.msg : data.msg);
                        });
                    }, 'text');
                } else {
                    $.dialog.alert('请选择要删除的项');
                }
            });
        });
    </script>
}
